package shopping;

import java.util.Scanner;

public class app {
    public static void main(String[] args) {
        // 初始化一些商品
        Product sprite = new Product("雪碧", "饮料", 3.0, 5);
        Product coke = new Product("可乐", "饮料", 3.5, 5);
        Product apple = new Product("苹果", "水果", 5.0, 5);

        shoppingcart cart = new shoppingcart();

        Scanner scanner = new Scanner(System.in);
        boolean flag = true;
        while (flag) {
            System.out.println("请选择操作：1.选择商品添加到购物车 2.查看购物车  3.结算 4.退出");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入商品名称（雪碧、可乐、苹果）");
                    String productName = scanner.next();
                    Product selectedProduct = null;
                    if ("雪碧".equals(productName)) {
                        selectedProduct = sprite;
                    } else if ("可乐".equals(productName)) {
                        selectedProduct = coke;
                    } else if ("苹果".equals(productName)) {
                        selectedProduct = apple;
                    }

                    System.out.println("请输入要添加的数量：");
                    int quantity = scanner.nextInt();
                    cart.addProduct(selectedProduct, quantity);
                    break;
                case 2:
                    cart.viewCart();
                    break;
                case 3:
                    double totalPrice = cart.checkout();
                    System.out.println("本次购物总价为：" + totalPrice + " 元");
                    break;
                case 4:
                    flag = false;
                    break;

                default:
                    System.out.println("无效的选择，请重新输入！");
            }
        }

        scanner.close();
    }
}
